function [ imOut ] = drawsegment( bwImage, A,B, theColor )
%DRAWSEGMENT Draw segment on BW image between two pixels
%   Input Arguments
%
%   bwImage - binary image on which to draw the line
%   A - pixel endpoint A
%   B - pixel endpoint B
%   the color = 1 for white or 0 for black
%
% Return Value - imOut = image with line drawn on it

     
    %Get the image size
    [r,c] = size(bwImage);                 
    
    %Get a set of row points for the line
    rpts = linspace(A(1,1),B(1,1),100);   
    
    %Get a set of column points for the line 
    cpts = linspace(A(1,2),B(1,2),100);   
    
    %Get a linear index for the image
    index = sub2ind([r c],round(rpts),round(cpts));  %# Compute a linear index
    
    %# Set the segment points to black or white
    imOut = bwImage;
    imOut(index) = theColor;

end

